<template>
  <div id="peopleInfo" class="p-2 addListBox">
    <div v-if="route.query.type == 'add'" style="margin: 20px 10px;font-weight: 600;font-size: 26px;display:flex;align-items: center;">添加人员信息</div>
    <div v-else style="margin: 20px 10px;font-weight: 600;font-size: 26px;display:flex;align-items: center;">修改人员信息</div>
    <el-card shadow="never">
      <el-table v-loading="loading" :data="peopleInfoList">
        <el-table-column align="center" width="130px" fixed>
          <template #header>
            <div>公司名称 <span style="color: #ff0000;">*</span> <br /></div>
          </template>
          <template #default="scope">
            <el-select
              class="slese"
              v-model="scope.row.companyId"
              placeholder="请选择公司"
              ref="selectRef"
              @change="infoChanged($event,scope.row,'companyId')"
            >
              <el-option
                class="communityDropdown"
                v-for="item in companyList"
                :key="item.companyId"
                :label="item.companyName"
                :value="item.companyId"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" width="130px" fixed>
          <template #header>
            <div>项目名称 <span style="color: #ff0000;">*</span> <br /></div>
          </template>
          <template #default="scope">
            <el-select
              class="slese"
              @visible-change="projectHandleVisibleChange($event,scope)"
              v-model="scope.row.projectId"
              placeholder="请选择项目"
              ref="selectRef"
              @change="infoChanged($event,scope.row,'projectId')"
              filterable
              :filter-method="getScollProjectList"
            >
              <el-option
                class="projectDropdown"
                v-for="item in projectList"
                :key="item.projectId"
                :label="item.projectName"
                :value="item.projectId"
              />
              <p class="el-select-dropdown__empty" v-show="loadingmore">加载中</p>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px" fixed>
          <template #header>
            <div>姓名 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.name" placeholder="姓名" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="160px">
          <template #header>
            <div>性别 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-radio-group v-model="scope.row.sex">
              <el-radio value="男" size="large">男</el-radio>
              <el-radio value="女" size="large">女</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
        <el-table-column align="center" width="160px">
          <template #header>
            <div>入职时间 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-date-picker
              clearable
              v-model="scope.row.entryTime"
              type="date"
              value-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择入职时间"
              @change="changeContractEndDate(scope.row)"
            ></el-date-picker>
          </template>
        </el-table-column>
        <el-table-column align="center" width="130px">
          <template #header>
            <div>岗位 <span style="color: #ff0000;">*</span> <br /></div>
          </template>
          <template #default="scope">
            <el-select class="slese" v-model="scope.row.postId" placeholder="请选择岗位" ref="selectRef" @change="postChanged($event,scope.row)">
              <el-option class="communityDropdown" v-for="item in postList" :key="item.postId" :label="item.post" :value="item.postId" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" width="180px">
          <template #header>
            <div>身份证号 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.identityCard" placeholder="身份证号" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="130px">
          <template #header>
            <div>联系电话 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.phone" placeholder="联系电话" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="180px" label="家庭住址">
          <template #default="scope">
            <el-input v-model="scope.row.address" placeholder="家庭住址" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="160px">
          <template #header>
            <div>是否缴纳社保 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-radio-group v-model="scope.row.isSbPayment">
              <el-radio value="1" size="large">是</el-radio>
              <el-radio value="0" size="large">否</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
        <el-table-column align="center" width="160px" label="社保缴纳日期">
          <template #default="scope">
            <el-date-picker
              clearable
              v-model="scope.row.sbPaymentDate"
              type="date"
              value-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择社保缴纳日期"
            ></el-date-picker>
          </template>
        </el-table-column>
        <el-table-column align="center" width="180px">
          <template #header>
            <div>银行卡号 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.bankNumber" placeholder="银行卡号" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px">
          <template #header>
            <div>合同签署次数 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.contractCount" placeholder="合同签署次数" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px">
          <template #header>
            <div>合同总年限 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-select v-model="scope.row.contractDuration" placeholder="请选择合同总年限" clearable @change="changeContractEndDate(scope.row)">
              <el-option v-for="dict in people_contract_duration" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" width="160px">
          <template #header>
            <div>合同到期时间 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-date-picker
              clearable
              v-model="scope.row.contractEndDate"
              type="date"
              value-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择合同到期时间"
              @change="changeContractDuration(scope.row)"
            ></el-date-picker>
          </template>
        </el-table-column>
        <!-- 在职人员 -->
        <el-table-column align="center" width="150px" label="物业证件">
          <template #default="scope">
            <el-select class="slese" multiple v-model="scope.row.certificateIdArr" placeholder="请选择物业证件" ref="selectRef">
              <el-option
                class="communityDropdown"
                v-for="item in certificateList"
                :key="item.certificateId"
                :label="item.certificateName"
                :value="item.certificateId"
              />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" width="160px">
          <template #header>
            <div>派遣流程 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-radio-group v-model="scope.row.dispatchStatus">
              <el-radio value="1" size="large">是</el-radio>
              <el-radio value="0" size="large">否</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px" label="基础工资">
          <template #default="scope">
            <el-input v-model="scope.row.basePay" placeholder="基础工资" @input="changeSalaryPayable(scope.row)" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px" label="岗位津贴">
          <template #default="scope">
            <el-input v-model="scope.row.postAllowance" placeholder="岗位津贴" @input="changeSalaryPayable(scope.row)" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px" label="其他补贴">
          <template #default="scope">
            <el-input v-model="scope.row.otherAllowance" placeholder="其他补贴" @input="changeSalaryPayable(scope.row)" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px" label="服装补贴">
          <template #default="scope">
            <el-input v-model="scope.row.clothingAllowance" placeholder="服装补贴" @input="changeSalaryPayable(scope.row)" />
          </template>
        </el-table-column>
        <el-table-column align="center" width="100px">
          <template #header>
            <div>实发工资 <span style="color: #ff0000;">*</span></div>
          </template>
          <template #default="scope">
            <el-input v-model="scope.row.salaryPayable" placeholder="实发工资" disabled />
          </template>
        </el-table-column>
        <!-- <el-table-column align="center" width="160px" label="扣除餐补状态">
          <template #default="scope">
            <el-radio-group v-model="scope.row.deductingMealAllowanceStatus">
              <el-radio value="1" size="large">是</el-radio>
              <el-radio value="0" size="large">否</el-radio>
            </el-radio-group>
          </template>
        </el-table-column> -->
        <el-table-column align="center" width="100px" label="请假天数">
          <template #default="scope">
            <el-input v-model="scope.row.leaveDays" placeholder="请假天数" />
          </template>
        </el-table-column>
        <!-- 离职人员 -->
        <el-table-column align="center" width="160px" label="离职时间" v-if="route.query.type=='edit'">
          <template #default="scope">
            <el-date-picker
              clearable
              v-model="scope.row.resignationTime"
              type="date"
              value-format="YYYY-MM-DD HH:mm:ss"
              placeholder="请选择离职时间"
              @change="isReignation(scope.row)"
            ></el-date-picker>
          </template>
        </el-table-column>
        <el-table-column align="center" width="150px" label="备注">
          <template #default="scope">
            <el-input v-model="scope.row.remark" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" placeholder="备注" />
          </template>
        </el-table-column>

        <!-- <el-table-column v-if="route.query.type == 'add'" label="操作" align="center" class-name="small-padding fixed-width" width="50px">
          <template #default="scope">
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="peopleInfoList = peopleInfoList.filter(item => item != scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column> -->
      </el-table>
    </el-card>
    <div style="display: flex;justify-content: center;margin-top: 20px;">
      <!-- <el-button v-if="route.query.type == 'add'" type="primary" icon="Plus" @click="addLine">追加一条</el-button> -->
      <el-button v-if="route.query.type == 'add'" type="success" icon="Position" @click="handleQuery">提交</el-button>
      <el-button v-else type="success" icon="Position" @click="handleQuery">提交修改</el-button>
      <el-button @click="goBack">返 回</el-button>
    </div>
  </div>
</template>

<script setup name="AssetCataAdd" lang="ts">
import { listCompany } from '@/api/business/company';
import { listProject } from '@/api/business/project';
import { listPost } from '@/api/business/post';
import { listCertificate } from '@/api/business/certificate';
import { addPeopleInfo, updatePeopleInfo, getPeopleInfo, addPeopleBatchInfo, updatePeopleBatchInfo, getPeopleBatchInfo   } from '@/api/business/peopleInfo';
import useCompanyStore from '@/store/modules/company';
import { addDays, differenceInDays } from 'date-fns';

const route = useRoute()
const useCompany = useCompanyStore();
const communitySwitchType = ref(true);
const categorySwitchType = ref(true);
const companyList = ref()
const projectList = ref()
const postList = ref()
const certificateList = ref()
const peopleInfoList = ref([]);
const listItem = {
  companyId: undefined,
  projectId: undefined,
  name: undefined,
  sex: '男',
  entryTime: undefined,
  postId: undefined,
  identityCard: undefined,
  phone: undefined,
  address: undefined,
  isSbPayment: '0',
  sbPaymentDate: undefined,
  bankNumber: undefined,
  contractCount: '1',
  contractDuration: '1',
  contractEndDate: undefined,
  certificateIdArr:undefined,
  certificateId:undefined,
  dispatchStatus: '1',
  basePay: undefined,
  postAllowance: undefined,
  otherAllowance: undefined,
  clothingAllowance: undefined,
  salaryPayable: undefined,
  deductingMealAllowanceStatus: '0',
  leaveDays: undefined,
  remark: undefined,
  status:'0'
}
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { people_contract_duration } = toRefs<any>(proxy?.useDict('people_contract_duration'));

const loading = ref(true);
const companyQueryParams = ref({
  pageNum: 1,
  pageSize: 100,
  companyId: undefined,
})
const projectQueryParams = ref({
  pageNum: 1,
  pageSize: 10,
  companyId: undefined,
  projectName:undefined
})
const postQueryParams = ref({
  pageNum: 1,
  pageSize: undefined
})
const certificateQueryParams = ref({
  pageNum: 1,
  pageSize: undefined
})

const projectTotal = ref(0);

// 追加一条
const addLine = () => {
  if(peopleInfoList.value.length > 0) {
    communitySwitchType.value?listItem.projectId=peopleInfoList.value[0].projectId:undefined
    categorySwitchType.value?listItem.companyId=peopleInfoList.value[0].companyId:undefined
  }
  peopleInfoList.value.push(JSON.parse(JSON.stringify(listItem)))
}

const hasNoEmptyValues = () => {
  let flag = true
  for(let i=0;i<peopleInfoList.value.length;i++) {
    peopleInfoList.value[i].basePay = peopleInfoList.value[i].basePay ? peopleInfoList.value[i].basePay:0
    peopleInfoList.value[i].postAllowance = peopleInfoList.value[i].postAllowance ? peopleInfoList.value[i].postAllowance:0
    peopleInfoList.value[i].otherAllowance = peopleInfoList.value[i].otherAllowance ? peopleInfoList.value[i].otherAllowance:0
    peopleInfoList.value[i].clothingAllowance = peopleInfoList.value[i].clothingAllowance ? peopleInfoList.value[i].clothingAllowance:0
    if(route.query.type == 'edit') {
      if(peopleInfoList.value[i].projectId == '' || peopleInfoList.value[i].projectId == null || peopleInfoList.value[i].name == '' || peopleInfoList.value[i].name == null || peopleInfoList.value[i].sex == '' || peopleInfoList.value[i].sex == null || peopleInfoList.value[i].entryTime == '' || peopleInfoList.value[i].entryTime == null || peopleInfoList.value[i].postId == '' || peopleInfoList.value[i].postId == null || peopleInfoList.value[i].identityCard == '' || peopleInfoList.value[i].identityCard == null || peopleInfoList.value[i].phone == '' || peopleInfoList.value[i].phone == null || peopleInfoList.value[i].isSbPayment == '' || peopleInfoList.value[i].isSbPayment == null || peopleInfoList.value[i].bankNumber == '' || peopleInfoList.value[i].bankNumber == null || peopleInfoList.value[i].contractCount == '' || peopleInfoList.value[i].contractCount == null || peopleInfoList.value[i].contractDuration == '' || peopleInfoList.value[i].contractDuration == null || peopleInfoList.value[i].contractEndDate == '' || peopleInfoList.value[i].contractEndDate == null || peopleInfoList.value[i].dispatchStatus == '' || peopleInfoList.value[i].dispatchStatus == null || peopleInfoList.value[i].salaryPayable == '' || peopleInfoList.value[i].salaryPayable == null){
        ElMessage.error('请将信息填写完成！')
        return false
      }
      if (i==peopleInfoList.value.length-1) {
        return true
      }
    }else {
      if(peopleInfoList.value[i].projectId == '' || peopleInfoList.value[i].projectId == null || peopleInfoList.value[i].name == '' || peopleInfoList.value[i].name == null || peopleInfoList.value[i].sex == '' || peopleInfoList.value[i].sex == null || peopleInfoList.value[i].entryTime == '' || peopleInfoList.value[i].entryTime == null || peopleInfoList.value[i].postId == '' || peopleInfoList.value[i].postId == null || peopleInfoList.value[i].identityCard == '' || peopleInfoList.value[i].identityCard == null || peopleInfoList.value[i].phone == '' || peopleInfoList.value[i].phone == null || peopleInfoList.value[i].isSbPayment == '' || peopleInfoList.value[i].isSbPayment == null || peopleInfoList.value[i].bankNumber == '' || peopleInfoList.value[i].bankNumber == null || peopleInfoList.value[i].contractCount == '' || peopleInfoList.value[i].contractCount == null || peopleInfoList.value[i].contractDuration == '' || peopleInfoList.value[i].contractDuration == null || peopleInfoList.value[i].contractEndDate == '' || peopleInfoList.value[i].contractEndDate == null || peopleInfoList.value[i].dispatchStatus == '' || peopleInfoList.value[i].dispatchStatus == null || peopleInfoList.value[i].salaryPayable == '' || peopleInfoList.value[i].salaryPayable == null){
        ElMessage.error('请将信息填写完成！')
        return false
      }
      if (i==peopleInfoList.value.length-1) {
        return true
      }
    }
  }
  return flag
}

// 提交全部
/* const handleQuery = async () => {
  if(hasNoEmptyValues()) {
    if(route.query.type == 'edit') {
      await updatePeopleBatchInfo({'hrmsPeopleInfoListBo':peopleInfoList.value}).then(() =>  {proxy?.$modal.msgSuccess("修改成功");});
      await goBack()
    }else {
      await addPeopleBatchInfo({'hrmsPeopleInfoListBo':peopleInfoList.value}).then((res) =>  {
        proxy?.$modal.msgSuccess("新增成功");
      });
      await goBack()
    }
  }
} */

// 提交单个
const handleQuery = async () => {
  if(hasNoEmptyValues()) {
    if(peopleInfoList.value[0]?.certificateIdArr !=null && peopleInfoList.value[0]?.certificateIdArr !=undefined && JSON.stringify(peopleInfoList.value[0]?.certificateIdArr)!='[]'){
      let arr = JSON.parse(JSON.stringify(peopleInfoList.value[0]?.certificateIdArr))
      peopleInfoList.value[0].certificateId = arr.join('、')
    }else if(peopleInfoList.value[0]?.certificateIdArr !=null && peopleInfoList.value[0]?.certificateIdArr !=undefined && JSON.stringify(peopleInfoList.value[0]?.certificateIdArr)=='[]'){
      peopleInfoList.value[0].certificateId = null
    }
    if(route.query.type == 'edit') {
      await updatePeopleInfo(peopleInfoList.value[0]).then(() =>  {proxy?.$modal.msgSuccess("修改成功");});
      await goBack()
      useCompany.getCompanyRYList()
    }else {
      await addPeopleInfo(peopleInfoList.value[0]).then((res) =>  {
        proxy?.$modal.msgSuccess("新增成功");
      });
      await goBack()
      useCompany.getCompanyRYList()
    }
  }
}

/** 返回 */
const goBack = () =>{
  const obj = { path: "/administration/staff" };
  proxy?.$tab.closeOpenPage(obj);
}

/** 查询所需列表 */
const getList = async () => {
  loading.value = true;
  companyQueryParams.value.companyId = projectQueryParams.value.companyId = useCompany.companyId
  const res = await listCompany(companyQueryParams.value);
  companyList.value = res.rows;
  /* const projectRes = await listProject(projectQueryParams.value);
  projectList.value = projectRes.rows
  projectTotal.value = projectRes.total; */
  if(peopleInfoList.value[0]){
    peopleInfoList.value.forEach(item => {
      item.companyId = useCompany.companyId
      item.projectId = undefined
    })
  }
  loading.value = false;
}

/** 获取岗位列表 */
const getPostList = async () => {
  const res = await listPost(postQueryParams.value);
  postList.value = res.rows;
}

/** 获取物业证书列表 */
const getCertificateList = async () => {
  const res = await listCertificate(certificateQueryParams.value);
  certificateList.value = res.rows;
}

const scopeProjectIndex=ref(0)
const projectHandleVisibleChange = (visible: any,scope:any) => {
  scopeProjectIndex.value = scope.$index
  try {
    if (visible) {
      // 如果下拉框显示
      let length = (document.getElementsByClassName('projectDropdown').length)/peopleInfoList.value.length*scopeProjectIndex.value
      setTimeout(() => {
        let projectDropdown: any = document.getElementsByClassName('projectDropdown')[length].parentElement.parentElement
        // 监听下拉框滚动事件
        projectDropdown.addEventListener('scroll', projectLoadNextPage,true)
      }, 300);
    } else {
      // 如果下拉框隐藏
      let length = (document.getElementsByClassName('projectDropdown').length)/peopleInfoList.value.length*scopeProjectIndex.value
      let projectDropdown: any = document.getElementsByClassName('projectDropdown')[length].parentElement.parentElement
      // 移除下拉框滚动事件监听
      projectDropdown.removeEventListener('scroll', projectLoadNextPage)
    }
  } catch (error) {}
}
const loadingmore = ref(false)
const loadingnomore = ref(false)
const projectLoadNextPage = async () => {
  let length = (document.getElementsByClassName('projectDropdown').length)/peopleInfoList.value.length*scopeProjectIndex.value
  let projectDropdown: any = document.getElementsByClassName('projectDropdown')[length].parentElement.parentElement
  // 判断下拉框是否触底
  if (projectDropdown.scrollTop + projectDropdown.clientHeight >= projectDropdown.scrollHeight - 2) {
    loadingnomore.value = false
    loadingmore.value = true
    if (projectList.value.length + 1 <= projectTotal.value && loadingmore.value) {
      projectQueryParams.value.pageNum ++
      const res = await listProject(projectQueryParams.value)
      projectList.value.length + 1 <= projectTotal.value?projectList.value.push(...res.rows):''
      loadingmore.value = false
    }else{
      loadingmore.value = false
      projectDropdown.removeEventListener('scroll', projectLoadNextPage)
      loadingnomore.value = true
    }
  } else {
    loadingnomore.value = true
  }
}

const getScollProjectList = async (value: string) => {
  if(projectQueryParams.value.companyId){
    if (value) {
      projectQueryParams.value.projectName = value
    }else{
      projectQueryParams.value.projectName = undefined
      projectQueryParams.value.pageNum = 1
    }
    const resProject = await listProject(projectQueryParams.value);
    projectList.value = resProject.rows
    projectTotal.value = resProject.total
  }
}

const infoChanged = async (id:string,row:any,type:any)=> {
  let arr
  if (type == 'companyId') {
    arr = companyList.value
    row.projectId = undefined
    getProjectList(id)
  }else{
    arr = projectList.value
  }
  arr.forEach((element) => {
    if(element[type] == id) {
      row[type] = element[type]
      if(communitySwitchType.value) {
        peopleInfoList.value.forEach(item => {
          item[type] = row[type]
        })
      }
    }
  });
}

/** 获取项目信息 */
const getProjectList = async (id?: any) => {
  projectQueryParams.value.companyId = id
  const projectRes = await listProject(projectQueryParams.value);
  projectList.value = projectRes.rows
  projectTotal.value = projectRes.total;
}

const postChanged = (id:string,row:any) =>{
  postList.value.forEach((element) => {
    if(element.postId == id) {
      row.postId = element.postId
      row.basePay = element.basePay
      row.postAllowance = element.postAllowance
      row.otherAllowance = element.otherAllowance
      row.clothingAllowance = element.clothingAllowance
      row.salaryPayable = element.salaryPayable
    }
  });
}

/* 修改基础工资等情况自动变化实发工资 */
const changeSalaryPayable = (row) =>{
  row.salaryPayable = row.basePay * 1 + row.postAllowance * 1 + row.otherAllowance * 1 + row.clothingAllowance * 1
}

/* 修改合同到期时间 */
const changeContractEndDate = (row) =>{
  if (row.entryTime) {
    let timer = addDays(row.entryTime, row.contractDuration*1*365)
    let date = new Date(timer);
    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    row.contractEndDate = y + '-' + m + '-' + d + ' 00:00:00'
  } else {
    row.contractEndDate = undefined
  }
}

/* 修改合同总年限 */
const changeContractDuration = (row) =>{
  if(row.contractEndDate && row.entryTime){
    if (differenceInDays(row.contractEndDate,row.entryTime)<365) {
      changeContractEndDate(row)
      ElMessage.warning('合同到期时间与入职时间相差至少为一年');
    }else{
      row.contractDuration = Math.floor((differenceInDays(row.contractEndDate,row.entryTime))/365).toString() //取整
    }
  }else{
    row.contractDuration = '1'
    changeContractEndDate(row)
  }
}

/* 离职了，传入离职信息 */
const isReignation = (row) => {
  if(row.resignationTime){
    row.status = '1'
  }else{
    row.status = '0'
  }
}

watch(()=> useCompany.companyId, (val) => {
  getList()
  if(!useCompany.companyId){
    projectList.value = []
  }
}, { immediate: true });

onMounted(async () => {
  route.query.type == 'edit' ? sessionStorage.setItem("searchFlag", '0') : sessionStorage.setItem("searchFlag", '1')
  // await getList()
  await getPostList()
  await getCertificateList()
  if(route.query.type == 'edit') {
    getPeopleInfo(route.query.id).then(res => {
      peopleInfoList.value = [res.data]
      if(peopleInfoList.value[0].contractDuration){
        peopleInfoList.value[0].contractDuration = peopleInfoList.value[0].contractDuration.toString()
      }
      if(peopleInfoList.value[0].certificateId){
        peopleInfoList.value[0].certificateIdArr = peopleInfoList.value[0].certificateId.split('、')
      }
      getProjectList(peopleInfoList.value[0].companyId)
    })
  }else{
    addLine()
    peopleInfoList.value.forEach(item => {
      item.companyId = useCompany.companyId
    })
  }
})
</script>
<style>
.el-table .cell {
  padding: 0 4px;
}
.addListBox .el-date-editor  {
  --el-date-editor-width: 122px;
}
.error-row {
  background:rgba(255, 0, 0, .3) !important;
}
</style>
